﻿
using System;
namespace NoNameGoServer.Client.Commands {
    public class PlayCommand : Command {
        private readonly char _letter;
        private readonly int _number;

		public PlayCommand(char letter, int number) {
            _letter = letter;
            _number = number;
        }

        public override void Execute(NNGSClient nngsClient) {
            string cmd = string.Format("{0}{1}\n", _letter, _number);
            nngsClient.SendAsync(this, cmd, null);
        }

		public override void ProcessReceivedLine(NNGSClient nngsClient, string line, out bool processed) {
			if (line.EndsWith("Unknown command.")) {
				processed = true;
				throw new NNGSClientException("'Unknown command.' received when trying to play '" + _letter + _number + "'");
			}

			base.ProcessReceivedLine(nngsClient, line, out processed);
		}

		public override string ToString() {
			return String.Format("play {0}{1}", _letter, _number);
		}
    }
}
